<?php

class AgencyModule extends fvModule {

	function __construct () {
		$moduleName = strtolower(substr(__CLASS__, 0, -6));

		parent::__construct(fvSite::$fvConfig->get("modules.{$moduleName}.smarty.template"),
		fvSite::$fvConfig->get("modules.{$moduleName}.smarty.compile"),
		fvSite::$Layoult);
	}
	
	function showEdit(){
	}

	function showRegister() {
		$Agency = new Agency();
		$request = fvRequest::getInstance();
		$m = $request->getRequestParameter('m');
		if ($m)
		{
			if ((strlen($m['password']) == 0)) {
            	unset($m['password']);
            	unset($m['password1']);
       		}
       		$cert = $request->getRequestParameter('cert');
       		$m['certificate_date'] = $cert['Date_Year'].'/'.$cert['Date_Month'].'/'.$cert['Date_Day'];
			$Agency->updateFromRequest($m);
			if ($Agency->save()) {
				fvResponce::getInstance()->setHeader('Id', $Agency->getPk());
				$this->setFlash("Данные успешно сохранены", self::$FLASH_SUCCESS);
			} else {
				fvResponce::getInstance()->setHeader('X-JSON', json_encode($Agency->getValidationResult()));
				$this->setFlash("Ошибка при сохранении данных проверьте правильность введенных данных", self::$FLASH_ERROR);
			}
			return $this->__display("show_thanks.tpl");
		}
		else
		{
			$this->__assign(array(
			'Agency' => $Agency,
			'AgencyError' => $Agency->getValidationResult(),
			'CityManager' => CityManager::getInstance(),
			'TestModuleManager' => TestModuleManager::getInstance()->getAll('module_type=0'),
			'LegalFormManager' => LegalFormManager::getInstance(),
			'TaxationFormManager' => TaxationFormManager::getInstance(),
			));

			return $this->__display("show_full.tpl");
		}
	}
}
?>